<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="zh-cn" style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?=VIEW_TITLE?></title>
    <link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url('/assets/css/'); ?>my_common.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <style>
        .del:hover {
            transform: scale(1.3, 1.3);
        }

        .del {
            transition: all 0.3s;
        }
    </style>
</head>
<body>
<?php
$this->load->view('admin_header.php');
?>
<div class="container">
    <div id="main_div" style="max-width: 720px;margin: auto;">
        <div id="scroll_div" style="overflow-y: auto;overflow-x: hidden;">
            <div id="task_div">

            </div>
            <div>
                <nav style="text-align: center;">
                    <ul class="pagination" id="page_ul">

                    </ul>
                </nav>
            </div>
        </div>

    </div>
</div>
<?php
$this->load->view('footer.php');
?>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
<script src="<?php echo base_url('/assets/js/'); ?>common.js"></script>
<script>
    var w_width = document.documentElement.clientWidth;
    var w_height = document.documentElement.clientHeight;
    var scroll_div_height = w_height - 180;
    $('#scroll_div').height(scroll_div_height + 'px');
    var this_page = 1;
    var this_rows = 5;
    var this_page_sum = 0;
    var this_del_id = 0;
    var this_manager_id = 0;
    var this_translation_article_id = 0;

    function getTaskJson() {
        $.ajax({
            url: '<?php echo site_url('taskworker/getMyTaskJson');?>',
            type: 'post',
            dataType: 'json',
            data: {
                page: this_page,
                rows: this_rows
            },
            success: function (data) {
                buildTask(data['list']);
                buildPageUl(data['count_all']);
            }
        });
    }
    function getPage(page) {
        this_page = page;
        getTaskJson();
    }

    function nextPage() {
        if (this_page < this_page_sum) {
            ++this_page;
        }
        getPage(this_page);
    }
    function lastPage() {
        if (this_page != 1) {
            --this_page;
        }
        getPage(this_page);
    }

    function buildPageUl(count_all) {
        $('#page_ul').empty();
        var page_num = Math.ceil(count_all / this_rows);
        this_page_sum = page_num;
        var html = '';
        html += '<li><a href="javascript:getPage(1)">&laquo;</a></li><li class=""><a href="javascript:lastPage()">上一页</a></li>';
        for (var i = 0; i < page_num; i++) {
            if (this_page == (i + 1)) {
                html += '<li class="active"><a href="javascript:getPage(' + (i + 1) + ')">' + (i + 1) + '</a></li>';
            } else {
                html += '<li><a href="javascript:getPage(' + (i + 1) + ')">' + (i + 1) + '</a></li>';
            }
        }
        html += '<li class=""><a href="javascript:nextPage()">下一页</a></li><li><a href="javascript:getPage(' + page_num + ')">&raquo;</a></li>';
        $('#page_ul').append(html);
    }

    function buildTask(task_list) {
        var html = '';
        var len = task_list.length;
        for (var i = 0; i < len; i++) {
            html += '<div class="panel panel-default" id="task_main_div_' + task_list[i]['id'] + '">';
            html += '<div class="panel-body" style="position: relative;">';
            html += '<div style="text-align: center">' + task_list[i]["title"] + '</div>';
            if (task_list[i]['is_proofreaded'] != 2) {
                html += '<div style="float:left;text-align: center;margin-top: 20px;width: 33.3%;">';
                if (task_list[i]['is_received'] == 0) {
                    html += '<button type="button" class="btn btn-default" disabled="disabled" style="width: 82px;">未领取</button>';
                } else if (task_list[i]['is_received'] == 1) {
                    html += '<button type="button" class="btn btn-default" disabled="disabled" style="width: 82px;">已领取</button>';
                } else if (task_list[i]['is_received'] == 2) {
                    html += '<button type="button" class="btn btn-default" disabled ="disabled" style ="width: 82px;">已领取</button>';
                }
                html += '</div><div style = "float:left;text-align:center;margin-top:20px;width:33.3%;">';
                if (task_list[i]['is_translationed'] == 0) {
                    html += '<button type = "button" class="btn btn-default" disabled="disabled" style="width:82px;">翻译</button>';
                } else if (task_list[i]['is_translationed'] == 1) {
                    html += '<button type="button" class= "btn btn-default" disabled="disabled" style="width:82px;">翻译中</button>';
                } else if (task_list[i]['is_translationed'] == 2) {
                    html += '<button type = "button" class= "btn btn-default" disabled="disabled" style="width: 82px;">已翻译</button>';
                }
                html += '</div><div style="float:left;text-align:center;margin-top:20px;width:33.3%;">';
                if (task_list[i]['is_proofreaded'] == 0) {
                    if (task_list[i]['is_translationed'] != 2) {
                        html += '<button type="button" class="btn btn-default" disabled="disabled" style="width: 82px;">未校对</button>';
                    } else {
                        html += '<button type="button" class="btn btn-default btn-primary" style="width: 82px;" onclick="jiaodui(' + task_list[i]['id'] + ',' + task_list[i]['is_translationed'] + ',' + task_list[i]['is_proofreaded'] + ')">未校对</button>';
                    }
                } else if (task_list[i]['is_proofreaded'] == 1) {
                    html += '<button type="button" class="btn btn-default btn-primary" style="width: 82px;" onclick="jiaodui(' + task_list[i]['id'] + ',' + task_list[i]['is_translationed'] + ',' + task_list[i]['is_proofreaded'] + ')">校对中</button>';
                } else if (task_list[i]['is_proofreaded'] == 2) {
                    html += '<button type="button" class="btn btn-default btn-success" disabled="disabled" style="width: 82px;">已校对</button>';
                }
                html += '</div>';
            } else {
                html += '<div class="row" style="line-height: 54px;text-align: center;">';
                html += '<span class="col-xs-4 col-sm-4 col-md-4" style="">分数:' + task_list[i]['score'] + '</span>';
                html += '<span class="col-xs-4 col-sm-4 col-md-4" style="">译员名:' + task_list[i]['ta_name'] + '</span>';
                html += '<span class="col-xs-4 col-sm-4 col-md-4" style="">任务专员名:' + task_list[i]['oa_name'] + '</span>';
                html += '</div>';
            }
            html += '</div>'
            html += '</div>';
        }
        $('#task_div').empty();
        $('#task_div').append(html);
    }
    getPage(this_page);
    function jiaodui(manager_id, is_translationed, is_proofreaded) {
        if (is_translationed != 2) {
            alert('该文章译员尚未翻译完毕,请等待译员提交!');
            return false;
        }
        window.location.href = "<?php echo site_url('taskworker/proofread?manager_id=')?>" + manager_id;
    }

</script>
</body>
</html>